
$(function() {
	Tip.supplier();

	$('#supplier').blur(function() {
		var a = $(this).val();
		Pay.supplier(a);
		
		var body = { };
		body.id = a;
		$.getJSON('contact.php?do=Supplier.ajax_id', body, function(json) {
			$("#c_name").val(json.name);
			$("#c_fullname").val(json.fullname);
			$("#c_address").val(json.address);
			$("#c_web").val(json.url);
		});
		
		var body = {};
		body.q = a;
		
		$.getJSON('finance.php?do=PaymentMy.ajax_linkman', body, function(json) {			
			linkman(json);
		});
	});
	
	$("#label_linkman").hide();
	
	new $.cleditor("content", {width:480, height:220});
    cleditor.focus();
});

function linkman(a) {		
	$select = $("#supplier_linkman");		
	$select.empty();
	count = 0;
	$.each(a, function(k, v) {
    	var item = new Option(v.name, v.id);
    	$select[0].options.add(item);
    	
    	if (count == 1) {
    		_link_man(v.id, false);
    	}
    	
    	count++;
    });
	
	$select.change(function() {
		var id = $(this).val();
		_link_man(id, true);
	}); 
}

function _link_man(id, select) {
	var url = 'info.php?do=Contact.ajax_id&q=' + id;
	$.getJSON(url, function(json) {
		var aaa = Supplier.aaa();
		if (select || aaa) {
			$("#c_contact").val(json.name);
			$("#c_mobile").val(json.mobile);
			$("#c_tel").val(json.tel);
			$("#c_fax").val(json.fax);
			$("#c_email").val(json.email);
			
			$("#to").val(json.email);
		}
	});
}
